package com.galaxy.service.config.condition;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.util.StringUtils;

/**
 * 环境配置条件,判断是否需要适合消息生产者配置
 * @author caijinbang
 * @date 2018/9/18 00:39
 */
public class MqProducerCondition implements Condition {

  @Override
  public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
    //判断当前环境开关是否开启
    String isOnOff = conditionContext.getEnvironment().getProperty("rocketmq.producer.isOnOff");
    //当且仅当值为on时，返回true
    if(!StringUtils.isEmpty(isOnOff) && isOnOff.equalsIgnoreCase("on")){
      return true;
    }
    return false;
  }
}
